# -*- coding: utf-8 -*- 

import wx
import os
#import chardet
  
#import the newly created GUI file 
import main  
class MainFrame(main.MyFrame1): 
    def __init__(self,parent): 
        main.MyFrame1.__init__(self,parent)
        #载入文件
        path = './'
        filename = 'note.txt'
        if not os.path.exists(filename):
            try:
                fp = open(filename,'wb')
                fp.write('')
                fp.close()
            except:
                pass
        else:
            try:
                fp = open(filename,'rb')
                word = fp.read()
                fp.close()
                #判断编码
                #chardit = chardet.detect(word)
                #chardit['encoding']
                word = word.decode('utf-8').encode('gbk')
                self.m_textCtrl1.SetValue(str(word))
            except:
                pass

    def record(self,event): 
        #获取参数
        word = str(self.m_textCtrl1.GetValue().encode('utf-8'))
        #写入文件
        filename = 'note.txt'
        try:
            fp = open(filename,'wb')
            fp.write(word)
            fp.close()
        except:
            pass
        #self.m_textCtrl1.SetValue(str("Wrong"))
        
app = wx.App(False) 
frame = MainFrame(None) 
frame.Show(True) 
#start the applications 
app.MainLoop()  